<template>
  <div>
    <!-- 顶部导航栏 -->
    <el-menu
      class="nav"
      :default-active="activeIndex"
      mode="horizontal"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
      router
    >
      <el-menu-item index="/index">首页</el-menu-item>
      <template v-if="isLogin">
        <el-menu-item index="/personal">{{username}}</el-menu-item>
        <el-menu-item index="#">账户充值</el-menu-item>
        <el-menu-item @click="dialogVisible=true">注销</el-menu-item>
      </template>
      <template v-else>
        <el-menu-item index="/login">登录</el-menu-item>
        <el-menu-item index="/register">快速注册</el-menu-item>
      </template>
      <el-menu-item index="5">帮助</el-menu-item>
    </el-menu>
    <!-- 下面的导航栏导航栏 -->
    <el-menu
      class="home_navbar"
      :default-active="activeIndex"
      mode="horizontal"
      background-color="#1e489a"
      text-color="#fff"
      active-text-color="#fff"
      active-background-color="pink"
      router
    >
      <el-menu-item index="/index">首页</el-menu-item>
      <el-menu-item index="/invest">我要投资</el-menu-item>
      <el-menu-item index="/borrow">我要借款</el-menu-item>
      <el-menu-item index="/personal" >个人中心</el-menu-item>
      <el-menu-item >新手指引</el-menu-item>
      <el-menu-item index="#">关于我们</el-menu-item>
    </el-menu>
    <div class="content">
      <router-view :username="username"></router-view>
    </div>
    <!-- 确认注销对话框 -->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="50%">
      <span>确定要退出登录？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="logout">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: "/personal",
      dialogVisible: false,
      isLogin: window.sessionStorage.getItem("isLogin"),
      username: window.sessionStorage.getItem("username"),
    };
  },
  methods: {
    //注销
    logout() {
      this.dialogVisible = false;
      window.sessionStorage.clear();
      this.$router.push("/login");
    }
  }
};
</script>

<style lang="less" scoped>
.nav.el-menu {
  height: 50px;
  display: flex;
  justify-content: flex-end;
  padding-right: 200px;
}
.nav .el-menu-item {
  height: 100% !important;
  line-height: 50px !important;
}
.home_navbar {
  height: 75px;
  display: flex;
  justify-content: center;
  padding-right: 100px;
  padding-left: 100px;
}
.home_navbar .el-menu-item{
    height: 100%;
    line-height: 75px;
    font-size:16px;
}
.content{
  padding: 15px 15%;
}
</style>